#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T,n,a[200005],f[1000005],f2[1000005],col[200005];ll ans;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        ans=0;
        memset(f,0,sizeof(f));
        for(int i=1;i<=n;i++){
            cin>>a[i];

            f2[i]=f[a[i]];
            f[a[i]]=i;
        }
        for(int i=1;i<=n;i++){
            if(f2[i]){
                if(col[f2[i]-1]>0) col[f2[i]]=-1;
                else                 col[f2[i]]=1;
                for(int j=f2[i]+1;j<i;j++){
                    col[j]=-col[f2[i]];
                }
                col[i]=col[f2[i]];
            }
        }
        for(int i=1;i<=n;i++){
            if(!col[i]) col[i]=-col[i-1];
            if(f2[i]&&col[f2[i]]==col[i]){
                ans+=a[i];
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
